<!DOCTYPE html>
<html>
  
  <head>
    {include file="common/meta" /}
  </head>
  
  <body>
    <div class="x-body">
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">
          <i class="layui-icon"></i>批量删除
        </button>

        <span class="x-right" style="line-height:40px">共有数据：{$count} 条</span>
      </xblock>

      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>配置的标题</th>
            <th>配置的名称</th>
            <th>配置的类型</th>
            <th>配置的值</th>
            <th>操作</th>
        </thead>

        <tbody>
          {foreach $conflist as $item}
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item.id}'>
                <i class="layui-icon">&#xe605;</i>
              </div>
            </td>
            <td>{$item.title}</td>
            <td>{$item.key}</td>

            {if condition="$item['type'] == 'text'"}
              <td>文本类型</td>
              <td>{$item.value}</td>
            {elseif condition="$item['type'] == 'file'" /}
              <td>文件类型</td>
              <td>
                <a href="{$item.value}" target="_blank">
                  <img src="{$item.value}" />
                </a>
              </td>
            {/if}

            <td class="td-manage">
              <a title="编辑" href="{:url('admin/config/edit',['conid'=>$item['id']])}">
                <i class="layui-icon">&#xe642;</i>
              </a>
              <a title="删除" onclick="member_del(this,`{$item.id}`)" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
              </a>
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>

      <div class="page">
        {$pagestr}
      </div>
    </div>
  </body>
</html>

<script>
  // 单个删除
  function member_del(obj,id){
      layer.confirm('确认要删除吗？',function(index){
          //发异步删除数据
          del(id)
      });
  }

  // 批量删除
  function delAll (argument) {

    var data = tableCheck.getData();

    layer.confirm('确认要删除吗？',function(index){
        //捉到所有被选中的，发异步进行删除
        var ids=data.join(',')
        del(ids)
    });
  }

  // 删除的异步请求
  function del(data){
    // 序列化 将对象转换为参数形式
    var params={
      ids:data
    }

    params=$.param(params)

    $.ajax({
      url:`{:url('admin/config/del')}`,
      type:'post',
      data:params,
      dataType:'json',
      success:function(success){
        layer.msg(success.msg,{icon:5,time:1000},function(){
          location.reload()
        })
      }
    })
  }
</script>